package
{
	import flash.filters.GlowFilter;
	
	import org.flixel.*;

	public class RoomButton extends FlxGroup
	{
		private var button:FlxSprite;
		private var hoverFilter:GlowFilter;
		private var overlapped:Boolean;
		private var onClick:Function;
		private var startX:int;
		private var startY:int;
		
		public function RoomButton(text:String, x:int, y:int, onClick:Function)
		{
			this.onClick = onClick;
			startX = x;
			startY = y;
			
			button = new FlxSprite(startX, startY, Res.RoomButtonBG);
			add(button);
			
			var buttonText:FlxText = new FlxText(button.x, button.y, button.width, text, false);
			buttonText.setFormat("Georgia", 24, 0x000000, "center", 0, true);
			buttonText.y = button.y + (button.height - buttonText.height)/2;
			add(buttonText);
			
			hoverFilter = new GlowFilter(0xFFFFFF, 0.8, 10, 10, 3);
			overlapped = false;
		}
		
		public override function update():void {
			if (button.overlapsPoint(FlxG.mouse.screenX,FlxG.mouse.screenY)) {
				if (!overlapped) {
					button.setFilter(hoverFilter);
					overlapped = true;
				}
			} else {
				if (overlapped) {
					button.removeFilter();
					overlapped = false;
				}
			}
			
			if (FlxG.mouse.justPressed() && overlapped) {
				onClick();
			}
		}
		
		public function get x():int { return startX; }
		public function get y():int { return startY; }
	}
}